import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes

@Component
class CustomErrorAttributes extends DefaultErrorAttributes{


    Map<String, Object> getErrorAttributes(
            RequestAttributes requestAttributes, boolean includeStackTrace) {
        Map<String, Object> attributes = super.getErrorAttributes(requestAttributes, includeStackTrace)
        attributes["foo"] = "bar"
        attributes
    }
}